package main

import (
	"encoding/xml"
	"fmt"
	"log"
	"strconv"
	"strings"
)

func main() {
	//bytes, e := ioutil.ReadFile("D:/Go/Development/src/learnGo/readWrite/test.txt")
	//if e != nil {
	//	panic(e)
	//}
	//log.Println("{" + string(bytes) + "}")
	xmltest()
	testStr()
	log.Println("yaml end")
	stringtest20200718()
}

func stringtest20200718() {
	// 字符一个字节序列
	str := "abcd"
	fmt.Println("  字符串=", str)
	fmt.Printf("字节序列=%v", []byte(str))
}

type Student struct {
	Name string `xml:"name,attr"`
	Age  int    `xml:"age,attr"`
}

func xmltest() {
	stu := Student{
		Name: "芮旭乐",
		Age:  27,
	}
	d, err := xml.Marshal(stu)
	if err == nil {
		log.Printf("%+v", string(d))
	}
	s := new(Student)
	err = xml.Unmarshal(d, &s)
	if err == nil {
		log.Println(s)
	}
}
func testCr() {
	//将int装换字符串
	s1 := strconv.Itoa(100)
	log.Printf("s=%+v", s1)
	n, err := strconv.Atoi("23232")
	if err == nil {
		log.Printf("成功转换1=%+v", n)
	}
	//参数1 数字的字符串形式
	//参数2 数字字符串的进制 比如二进制 八进制 十进制 十六进制
	//参数3 返回结果的bit大小 也就是int8 int16 int32 int64
	m, erro := strconv.ParseInt("100", 10, 8)
	if erro == nil {
		log.Printf("成功转换2=%+v", m)
	}
	f, err := strconv.ParseFloat("234.45", 10)
	if err == nil {
		log.Printf("%+v", f)
	}
}
func testStr() {
	s := "1,2,3,4,5,6"
	boo := strings.Contains(s, "5")
	log.Printf("该字符串是否包含5=%+v", boo)

	boo = strings.ContainsAny(s, "2dsjfhdsj")
	log.Printf("该字符串是否包含2dsjfhdsj中的任意字符=%v", boo)
	strSli := strings.Split(s, ",")
	log.Printf("将字符串装换为切片=%+v", strSli)
	bo := strings.HasPrefix(s, "1")
	log.Printf("该字符串是否已1开头=%+v", bo)
	b := strings.HasSuffix(s, "5")
	log.Printf("该字符串是否已5结尾=%+v", b)
	strjoin := strings.Join(strSli, "-/-")
	log.Printf("将该字符串数组装换为string=%+v", strjoin)
}
